#include <iostream>
#include <fstream>
#include <string>
#include <vector>

#include "main.h"
#include "error.h"
#include "parse.h"
#include "mem.h"

using namespace std;
int loadSrcFile(string fileName);

int main(int argc, char* argv[])
{
    return loadSrcFile("//home//nb0dy//Projects//nbXdy//bin//Debug//code.nbx");
}

int loadSrcFile(string fileName)
{
    vector<string> prgList;         // Buffer to hold the entire program in memory
    string srcLine;                 // Buffer to hold one line of source code
    int numLines = 0;               // Total number of lines read into memory
    int nLine = 0;                  // Index to those lines

    // Load the file
    ifstream srcFile(fileName.c_str());
        if(!srcFile)
            errorMessage(ERR_FILE_LOAD, fileName, NULL);

    // Read the entire program into memory
    while(getline(srcFile, srcLine, '\n'))
        prgList.push_back(srcLine);

    // Close the file
    srcFile.close();

    // Parse the program line by line
    numLines = prgList.size();
    while(nLine<numLines)
    {
        parse(prgList.at(nLine), nLine);
        nLine++;
    }

    // List the variables in memory
    listVars();

    return 0;
}
